package com.pro.common.user.task.service;

import com.pro.common.api.user.task.enums.EnumUserTaskStatus;
import com.pro.common.api.user.task.model.db.UserTaskStep;
import com.pro.common.user.task.dao.UserTaskStepDao;
import com.pro.framework.mybatisplus.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户任务服务
 */
@Service
@Slf4j
public class UserTaskStepService extends BaseService<UserTaskStepDao, UserTaskStep> {

    public List<UserTaskStep> getActiveList(UserTaskStep entity) {
        return this.lambdaQuery().setEntity(entity)
                .list();
    }


    public List<UserTaskStep> getListAsc(UserTaskStep param) {
        Long cursor = param.getCursor();
        Integer limit = param.getLimit();
        return this.lambdaQuery()
//                .select(
//                        UserTaskStep::getId,
//                        UserTaskStep::getUserId
//                )
//                .in(UserTaskStep::gets, failSet)
                .gt(null != cursor, UserTaskStep::getId, cursor)
//                .le(null != max, UserTaskStep::getId, max)
                .setEntity(param)
                .last("limit " + limit)
                .list();
    }

    /**
     * 最大的完成的Id = 最小的未完成的Id - 1
     */
    public Long getVirtualFinishMaxId(UserTaskStep param) {
        UserTaskStep item = this.lambdaQuery()
                .select(UserTaskStep::getId)
//                .eq(UserTaskStep::getStatus, EnumUserTaskStatus.PENDING)
                .setEntity(param)
                .orderByAsc(UserTaskStep::getId)
                .last("limit 1").one();
        return null == item ? null : item.getId() - 1;
    }
}
